<?php
/**
 *  $row[0] = id
 *  $row[1] = En_Sen
 */
function process_download($row,$path){
    print "start $row[0] ...\n"; 
    $filename = $path.$row[0].".wav";
    if(!file_exists($filename)){
        $objSoap = new SoapClient("https://tts.neospeech.com/soap_1_0.php?wsdl");
        try{
            $strResultArray = $objSoap->ConvertSimple(
                "fnsoxt@gmail.com",
                "df97b8fa75",
                "LoginKey",
                "6ac702430df10246ad1a",
                "TTS_KATE_DB",
                "FORMAT_WAV",
                $row[1]);
        }
        catch(SoapFault $e){
                print 'SoapFault exception: ' . $e->getMessage() . "\n";
                print "error-soap:{$row[0]}-{$strResultArray[3]}\n";
        }
        if($strResultArray[1] == "0" && $strResultArray[2] == "success"){
            soap_download($row[0],$strResultArray[3],$path);
       }
        else{
            print "error-query:" . $row[0] ."\t" .$row[2]."\n";
        }
    }
    else{
        print "pass {$row[0]}\n";
    }
}
function soap_download($word_id, $soap_id, $path){
    $objSoap_result = new SoapClient("https://tts.neospeech.com/soap_1_0.php?wsdl");
    $strResult = $objSoap_result->GetConversionStatus(
        "fnsoxt@gmail.com",
        "df97b8fa75",
        $soap_id);
    if($strResult[1] == "0" && $strResult[2] == "success"){
        system("wget -q --no-check-certificate " . $strResult[5] . " -O ".$path . $word_id.".wav",$retval);
        if($retval){
            print "error-download:{$word_id}-{$soap_id}\n";
        }
        else{
            print "sucess-download:{$word_id}-{$soap_id}\n";
        }
    }
    else{
        print "error-download-romote:" . $word_id . "-" . $soap_id . "\n";
    }
}
